package com.tiancikeji.zaoke.app.util;

public final class PriceUtil {

    public static final long LONG_COFF = 1000;

    public static final double COFF = LONG_COFF;

    public static final double EPSILON = 0.0001d;

    public static final double toDouble(Long value) {
        if (value == null) {
            return 0;
        }
        else {
            return toDouble(value.longValue());
        }
    }

    public static final double toDouble(long value) {
        return value / COFF;
    }

    public static final long fromDouble(Number value) {
        if (value == null) {
            return 0;
        }
        else {
            return fromDouble(value.doubleValue());
        }
    }

    public static final long fromDouble(double value) {
        value = Math.round(value * COFF);
        if (value > 0) {
            return (long) (value + EPSILON);
        }
        else {
            return (long) (value - EPSILON);
        }
    }

    public static double truncate(double money) {
        long longValue = fromDouble(money);
        longValue = ((longValue + 5) / 10) * 10;
        return toDouble(longValue);
    }

}
